> button 事件属性

button 事件属性

定义和用法

button 事件属性可返回一个整数,指示当事件被触发时哪个鼠标按键被点击。

语法

event.button=0|1|2
参数 描述
0 规定鼠标左键。
1 规定鼠标中键。
2 规定鼠标右键。

Internet Explorer 拥有不同的参数:

参数 描述
1 规定鼠标左键。
4 规定鼠标中键。
2 规定鼠标右键。

提示和注释

注释:对于惯用左手的鼠标配置,上面的参数是颠倒的。

提示:Mozilla 的 Ctrl–Click 参数是 2 (等价于右击)。

实例

The following example alerts which mouse button was clicked:

<html>
<head>
<script type="text/javascript">
function whichButton(event)
  {
    if (event.button==2)
      {
      alert("You clicked the right mouse button!")
      }
    else
      {
      alert("You clicked the left mouse button!")
      }
  }
</script>
</head>

<body onmousedown="whichButton(event)">
	
<p>Click in the document. An alert box will 
alert which mouse button you clicked.</p>

</body>
</html>

TIY

button
检测哪个鼠标键被点击了。
参考手册

W3c0.com 提供的内容仅用于培训。我们不保证内容的正确性。通过使用本站内容随之而来的风险与本站无关。W3c0 简体中文版的所有内容仅供测试,对任何法律问题及风险不承担任何责任。 当使用本站时,代表您已接受了本站的使用条款和隐私条款。版权所有,保留一切权利。 鲁ICP备15022115号